package com.hariro.json;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.hariro.helptools.HttpClientHelper;

public class New_Parsejson {
	private List<Map<String, Object>> list = null;

	public static String UPDATE_INFO;

	public List<Map<String, Object>> parserDataToList(String jsonString) {

		Log.i("json-------->", jsonString);
		list = new ArrayList<Map<String, Object>>();
		String data = new String(HttpClientHelper.loadByteFromURL(jsonString));
		Log.i("data-------->", data);
		try {
			if (data != null) {
				JSONObject obj = new JSONObject(data);
				UPDATE_INFO = obj.getString("nearestItemTips") + "";
				JSONArray itemList = obj.getJSONArray("itemList");

				for (int i = 0; i < itemList.length(); i++) {
					Map<String, Object> map = new HashMap<String, Object>();
					JSONObject objitem = itemList.getJSONObject(i);
					String showAt = objitem.getString("showAt");

					Log.i("showAt-------->", showAt);
					if (!showAt.equals("0")) {
						map.put("url", objitem.get("imgUrl"));
						map.put("typeName", objitem.getString("typeName"));
						map.put("picHeight", objitem.getString("picHeight"));
						map.put("picWidth", objitem.getString("picWidth"));
						map.put("title", objitem.getString("shareTitle"));
						map.put("timeStamp", objitem.getString("timeStamp"));
						map.put("itemId", objitem.getString("itemId"));
						map.put("typeId", objitem.getString("typeId"));
					} else {
						map.put("url", objitem.getString("url"));
						map.put("picHeight", objitem.getString("picHeight"));
						map.put("picWidth", objitem.getString("picWidth"));
						map.put("price", objitem.getString("price"));
						map.put("title", objitem.getString("title"));
						map.put("timeStamp", objitem.getString("timeStamp"));
						map.put("itemId", objitem.getString("itemId"));
						map.put("typeId", objitem.getString("typeId"));
					}
					map.put("nearestItemTips", obj.getString("nearestItemTips"));
					Log.i("nearestItemTips", obj.getString("nearestItemTips")
							+ "");
					list.add(map);
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
}
